package com.ctrip.framework.apollo.demo.spring.springBootDemo;

import com.ctrip.framework.apollo.demo.spring.springBootDemo.config.SampleRedisConfig;
import com.google.common.base.Charsets;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * @author Jason Song(song_s@ctrip.com)
 */
@SpringBootApplication(scanBasePackages = {"com.ctrip.framework.apollo.demo.spring.common",
    "com.ctrip.framework.apollo.demo.spring.springBootDemo"
})
public class SpringBootSampleApplication {

  @Autowired
  private  static SampleRedisConfig sampleRedisConfig;


  public static void main(String[] args) throws  Exception{
   new SpringApplicationBuilder(SpringBootSampleApplication.class).run(args);

//    ConfigurableApplicationContext context =
//            new SpringApplicationBuilder(SpringBootSampleApplication.class).run(args);
//    context.addApplicationListener(new ApplicationPidFileWriter());
//    context.addApplicationListener(new EmbeddedServerPortFileWriter());
//
//    while(true){}

  }

  private static void onKeyExit() {
    System.out.println("Press Enter to exit...");
    new Scanner(System.in).nextLine();
  }

  private static  void testSampleRedisConfigReadWhichNamespace() throws  Exception{
    while (true) {
      System.out.print("> ");
      String input = new BufferedReader(new InputStreamReader(System.in, Charsets.UTF_8)).readLine();
      if (input == null || input.length() == 0) {
        continue;
      }
      input = input.trim();
      if (input.equalsIgnoreCase("quit")) {
        System.exit(0);
      }
      System.out.println("value:"+sampleRedisConfig.getExpireSeconds());
    }
  }

}
